import { getCityListApi } from '@/api/product'

const state = {
//  城市列表数据
  cityList: []
}
const mutations = {
//  修改城市列表数据
  saveCityList (state, citys) {
    state.cityList = citys
  }
}
const actions = {
  async getCityList ({
    commit,
    state
  }) {
    //  发送请求获取城市列表
    if (!state.cityList.length) {
      const res = await getCityListApi()
      console.log(res)
      commit('saveCityList', res)
      return res
    }
    return state.cityList
  }
}
const getters = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
